<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
			label-width="68px">
			<el-form-item label="商户名" prop="shopName">
				<el-input v-model="queryParams.shopName" placeholder="请输入商户名" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="审核状态" prop="shopAudit">
				<el-select v-model="queryParams.shopAudit" placeholder="请选择审核状态" clearable>
					<el-option v-for="dict in dict.type.shop_audit" :key="dict.value" :label="dict.label"
						:value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<!-- <el-col :span="1.5">
				<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
					v-hasPermi="['shop:shop:add']">新增</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
					v-hasPermi="['shop:shop:edit']">修改</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
					@click="handleDelete" v-hasPermi="['shop:shop:remove']">删除</el-button>
			</el-col> -->
			<el-col :span="1.5">
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
					v-hasPermi="['shop:shop:export']">导出</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="shopList" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="商户名称" align="center" prop="shopName" />
			<el-table-column label="经营区域" align="center" prop="shopArea" />
			<el-table-column label="负责人" align="center" prop="perName" />
			<el-table-column label="注册时间" align="center" prop="shopCreateTime" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.shopCreateTime, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="审核状态" align="center" prop="shopAudit">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.shop_audit" :value="scope.row.shopAudit" />
				</template>
			</el-table-column>


			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
						v-hasPermi="['shop:shop:edit']">修改</el-button>
					<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
						v-hasPermi="['shop:shop:remove']">删除</el-button> -->
					<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
						v-hasPermi="['shop:shop:edit']">详情</el-button>
					<el-button size="mini" type="text" icon="el-icon-edit" @click="shenHe(scope.row)"
						v-hasPermi="['shop:shop:edit']">审核</el-button>
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
			@pagination="getList" />

		<!-- 添加或修改门店管理对话框 -->
		<el-dialog :title="title" :visible.sync="openShenHe" width="500px" append-to-body>
			<el-form ref="form" :model="form" label-width="100px">
				<el-form-item label="审核结果:">
					<el-radio v-model="form.shopAudit" label="1">审核通过</el-radio>
					<el-radio v-model="form.shopAudit" label="2">审核不通过</el-radio>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitFormShenHe">确 定</el-button>
				<el-button @click="cancelShenHe">取 消</el-button>
			</div>
		</el-dialog>

		<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
			<el-descriptions title="商户信息" :column="2" border>
				<el-descriptions-item>
					<template slot="label">
						商品名称
					</template>
					{{form.shopName}}
				</el-descriptions-item>
				<el-descriptions-item>
					<template slot="label">
						营业执照号码
					</template>
					{{form.shopNumber}}
				</el-descriptions-item>
				<el-descriptions-item>
					<template slot="label">
						负责人
					</template>
					{{form.perName}}
				</el-descriptions-item>
				<el-descriptions-item>
					<template slot="label">
						负责人手机号
					</template>
					{{form.perPhone}}
				</el-descriptions-item>
				<el-descriptions-item>
					<template slot="label">
						身份证号码
					</template>
					{{form.perIdcard}}
				</el-descriptions-item>
				<el-descriptions-item>
					<template slot="label">
						经营区域
					</template>
					{{form.shopArea}}
				</el-descriptions-item>
				<el-descriptions-item>
					<template slot="label">
						注册时间
					</template>
					{{form.shopCreateTime}}
				</el-descriptions-item>
				<el-descriptions-item>
					<template slot="label">
						审核状态
					</template>
					{{form.shopAudit == 0 ? '未审核' : (form.audit == 1 ? '已审核' : '已拒绝')}}
				</el-descriptions-item>
				<el-descriptions-item>
					<template slot="label">
						详细地址
					</template>
					{{form.shopAddress}}
				</el-descriptions-item>
				<el-descriptions-item>
					<template slot="label">
						商家介绍
					</template>
					{{form.shopIntro}}
				</el-descriptions-item>
			</el-descriptions>
			<el-descriptions title="商户照片" :column="1" style="margin-top: 20px;">
				<el-descriptions-item>
					<template slot="label">
						门面照片
					</template>
				</el-descriptions-item>
				<el-descriptions-item>
					<template slot="label">
						营业执照
					</template>
					<image-preview :src="form.shopLicence" :width="120" :height="100" />
				</el-descriptions-item>
				<el-descriptions-item>
					<template slot="label">
						身份证正面
					</template>
					<image-preview :src="form.cardFront" :width="120" :height="100" />
				</el-descriptions-item>
				<el-descriptions-item>
					<template slot="label">
						身份证反面
					</template>
					<image-preview :src="form.cardBack" :width="120" :height="100" />
				</el-descriptions-item>
			</el-descriptions>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<!-- <! 	<el-button @click="cancel">取 消</el-button> -->
				<el-button @click="cancel">关闭</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import {
		listShop,
		getShop,
		delShop,
		addShop,
		updateShop
	} from "@/api/shop/shop";

	export default {
		name: "Shop",
		dicts: ['shop_audit'],
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 门店管理表格数据
				shopList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				openShenHe: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					shopName: null,
					shopAudit: null,
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {

				}
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询门店管理列表 */
			getList() {
				this.loading = true;
				listShop(this.queryParams).then(response => {
					this.shopList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			cancelShenHe() {
				this.openShenHe = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					shopId: null,
					shopName: null,
					shopNumber: null,
					shopArea: null,
					shopAddress: null,
					shopIntro: null,
					shopAudit: null,
					shopCreateTime: null,
					shopLicence: null,
					cardFront: null,
					cardBack: null,
					shopMoney: null,
					accIncome: null,
					accOut: null,
					perName: null,
					perPhone: null,
					perPassword: null,
					perIdcard: null,
					storeName: null,
					week: null,
					startTime: null,
					endTime: null,
					longitude: null,
					latitude: null,
					star: null,
					sales: null
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.shopId)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},
			/** 新增按钮操作 */
			handleAdd() {
				this.reset();
				this.open = true;
				this.title = "添加门店管理";
			},
			/** 修改按钮操作 */
			handleUpdate(row) {
				this.reset();
				const shopId = row.shopId || this.ids
				getShop(shopId).then(response => {
					this.form = response.data;
					this.open = true;
					this.title = "详情";
				});
			},
			shenHe(row) {
				this.reset();
				const shopId = row.shopId || this.ids
				getShop(shopId).then(response => {
					this.form = response.data;
					this.openShenHe = true;
					this.title = "审核";
				});
			},
			/** 提交按钮 */
			submitForm() {


				updateShop(this.form).then(response => {
					this.$modal.msgSuccess("修改成功");
					this.open = false;
					this.getList();
				});

			},
			submitFormShenHe() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						if (this.form.shopId != null) {
							updateShop(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.openShenHe = false;
								this.getList();
							});
						} else {
							addShop(this.form).then(response => {
								this.$modal.msgSuccess("新增成功");
								this.ShenHe = false;
								this.getList();
							});
						}
					}
				});
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const shopIds = row.shopId || this.ids;
				this.$modal.confirm('是否确认删除门店管理编号为"' + shopIds + '"的数据项？').then(function() {
					return delShop(shopIds);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('shop/shop/export', {
					...this.queryParams
				}, `shop_${new Date().getTime()}.xlsx`)
			}
		}
	};
</script>
<style scoped>

</style>